import {Component, OnInit, ViewEncapsulation, ChangeDetectionStrategy} from '@angular/core';
import {ToolsService} from "@shared/service/tools/tools.service";
import {MineService} from "@mine/mine.service";
import {Subject} from "rxjs/Subject";
import {AuthService} from "@shared/service/auth/auth.service";
import {Router} from "@angular/router";

@Component({
  selector: 'setting',
  templateUrl: './setting.component.html',
  styleUrls: ['./setting.component.scss'],
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class SettingComponent implements OnInit {
  public ngUnsubscribe: Subject<void> = new Subject<void>();
  constructor(
    public toolservice: ToolsService,
    public mineService: MineService,
    public authservice: AuthService,
    public router: Router,
  ) {
  }

// 退出登录
  logout() {
    this.mineService.goLoginOut().takeUntil(this.ngUnsubscribe).subscribe(res => {
      if (res.result === '0') {
        this.toolservice.showToast('退出成功！');
        this.toolservice.hideLoading();
        this.authservice.logout();
        this.router.navigate(['']);
      } else {
        this.toolservice.hideLoading();
        this.toolservice.showToast('退出登录出错请刷新后重试', 1000);
      }
    });
  }

  ngOnInit() {
  }

}
